<template>
    <section>

        <br>


        <!--搜索结果表格-->
        <el-table
                :header-row-style="headerRowStyle"
                :data="tableData"
                stripe
                v-loading="listLoading"
                style="width: 100%;">
            <el-table-column
                    label="序号"
                    type="index"
                    width="70"
                    align="center">
            </el-table-column>

            <el-table-column
                    align="center"
                    label="标题"
                    prop="notification_title">
                <template slot-scope="scope">
                    {{scope.row.notification_title}}
                </template>
            </el-table-column>

            <el-table-column
                    align="center"
                    label="创建日期"
                    prop="gmt_created">
            </el-table-column>

            <el-table-column label="操作" align="left" width="200">
                <template slot-scope="scope">
                   <!-- <el-button
                            type="primary" plain=""
                            @click="download(scope.row.upload_notification_file.path)">下载通知书
                    </el-button>-->

                    <a :href="scope.row.upload_notification_file.path" :download="scope.row.notification_title+'.docx'">下载通知书</a>

                </template>
            </el-table-column>
        </el-table>

        <!--分页-->
        <el-col :span="24" class="toolbar">
            <el-pagination
                    style="text-align: center;"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :page-size="pager.page_size"
                    :page-sizes="pager.sizes"
                    background
                    :current-page="pager.page_current"
                    layout="prev,pager,next,sizes,total"
                    :total="pager.total">
            </el-pagination>
        </el-col>




    </section>
</template>

<script>
    import {getNoticeList,getReportsDetail,returnReport,saveScanId,issueReportNotice,createNotice} from '../../api/report_manager_api'
    import {upload_file,get_update_img,get_file,getResourceUrl} from "../../api/common";
    import dict from '../../common/js/dict';
    export default {
        computed:{
            base_url(){
               // return this.$store.state.res_url
               return ''
            }
        },
        data() {
            return {
                send_id:'',

                fileLists:[],
                issueReportDesc:'',
                submitReportDialog: false,
                dict:dict,
                currentYear: '2018',
                //表单header样式
                headerRowStyle: {
                    backgroundColor: "#ddd",
                    color: "#333",
                    textAlign: "center"
                },
                listLoading: false,
                //表格数据
                tableData: [],

                searchRules:{
                    year:{required:true,message:'请选择年份',trigger:'blur'}
                },
                //分页设置
                pager: {
                    sizes: [10, 20, 30, 40, 50],
                    total: 0,
                    page_size: 10,
                    page_current: 1
                },
                filters:{},
                timer:null,
                options: {
                    years: [],
                    check_result: dict.check_result,
                    manager_notice_status:dict.manager_notice_status
                }
            }
        },
        computed:{
            unit_id(){

                return this.$store.state.userInfo.unit_id
                // return this.$router.params.id || this.$store.state.userInfo.unit_id
            }
        },
        methods: {
            send(id){
                this.send_id = id
                this.submitReportDialog = true;
            },

            download(file_url){
              window.open(file_url)
            },
            formatCheckResult(row){
                if(row.check_result){
                    return dict.check_result[row.check_result];
                }else{
                    return '——';
                }
            },
            formatterStatus(row){
                return this.options.manager_notice_status[row.check_report_notice_status];
            },

            // 详情
            view(id) {
                this.$router.push('/manage/reports/detail/' + id);
            },
            //分页page_size发生改变
            handleSizeChange(val) {
                this.pager.page_current = 1;
                this.pager.page_size = val;
                this.getReports();
            },
            //分页page_current发生改变
            handleCurrentChange(val) {
                this.pager.page_current = val;
                this.getReports();
            },
            search(){
                this.pager.page_current = 1;
                this.getReports();
            },
            getReports(){
                this.listLoading = true;  //显示loading

                let condition = this.filters;
                let params = {
                    page_size: this.pager.page_size,
                    page_current: this.pager.page_current,
                    order_column:"gmt_modified",
                    order_by:"desc",
                    condition: Object.assign({},condition)

                };

                if (condition.check_report_status === ''){
                    params.condition.check_report_status='-2'
                }
                params.condition.school=true //请求学校的通知书列表

                params.condition.unit_id=this.unit_id //请求学校的id
                getNoticeList(params).then((res) => {
                    if (res.data.status == 200) {
                        this.listLoading = false;  //隐藏loading

                        let result = JSON.parse(res.data.datas);

                        console.log(result)
                        this.tableData = result.items



                        this.pager.total = result.total;
                    } else {
                        if (res.data.status == 401) {
                            this.$router.push('/login');
                        }
                        this.$message.error(res.data.status + " " + res.data.msg);
                    }
                });

            },
            reset(){
                this.$refs['filters'].resetFields();
                this.pager.page_current = 1;
                this.getReports();
                },
            initYears() {
                this.currentYear = (new Date()).getFullYear()+'';
                this.filters.year = this.currentYear;

                for (let i = this.currentYear; i >= 2018; i--) {
                    this.options.years.push(i);
                }
            },
            //初始化页面
            initData() {
                // this.initYears();

                clearInterval(this.timer)
                if (this.unit_id ){
                    this.getReports();
                }else{
                    this.timer = setInterval(this.initData,1000)
                }
            }
        },
        mounted() {
            this.$nextTick(function () {
                this.initData();
            })
        }
    }
</script>

<style scoped>

</style>
